import { defineStore } from "pinia";

export const useUserStore = defineStore('userStore',{
    state: () => {
        return {
            // 登录token
            token: '',
            // 登录的用户信息
            userInfo: {
                avatar: '',
                userName: '',
                sex: '',
                email: '',
                CreatedAt: ''
            },
            // 角色
            roles: []
        }
    },
    getters: {},
    actions: {
        // 设置登录token
        setToken(token: string) {
            this.token = token;
        },
        // 设置登录用户的信息
        setUserInfo(userInfo: any) {
            this.userInfo = userInfo;
        },
        // 更新部分信息
        setUserPartInfo(userInfo: any) {
            this.userInfo.avatar = userInfo.avatar;
            this.userInfo.userName = userInfo.userName;
            this.userInfo.sex = userInfo.sex;
        }
    },
    persist: true,
})